<?php


namespace app\admin\library\builder;


class Components
{
    public $key;

    public $name;

    protected $content;

    public $vars = [];

    public function __construct(array $args)
    {
        $this->name = strtolower((new \ReflectionClass($this))->getShortName());
        $this->content = file_get_contents(__DIR__ . '/tpl/' . $this->name . '.twig');
        $this->vars = $args;
    }

    public function addkey(KeyManager $key)
    {

        $this->vars['__KEY__'] = $key;
        $this->key = isset($args['key']) ? $this->name . '_' . $args['key'] : $key->apply($this->name);


    }

    public function render()
    {
        return $this->content;
    }
}